﻿using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace eDream.admin
{
    public partial class quanly_sanpham : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        
        }

        protected void grvpResult_Load(object sender, EventArgs e)
        {
            DataClasses1DataContext dx = new DataClasses1DataContext();
            try
            {
                dx.Connection.Open();
                var list = from k in dx.Product_tbs
                           select new { k.ID, k.image, k.Chietkhau, k.goiy, k.giamphantram, k.iflag, k.iProName, k.trangchu, k.iDongiamoi };
                grvpResult.DataSource = list;
                grvpResult.DataBind();
            }
            catch (Exception) { }
            finally { dx.Connection.Close(); }
        }

        protected void ASPxCallbackPanel1_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            if(e.Parameter=="save1")
                updata(false);
            else
                updata(true);
        }

        void updata(bool b)
        {
            string array = "";
            DataClasses1DataContext dx = new DataClasses1DataContext();
            try
            {
                dx.Connection.Open();
                int index = 0;
                for (int i = 0; i < grvpResult.VisibleRowCount; i++)
                {
                    GridViewDataColumn column1 = grvpResult.Columns["check"] as GridViewDataColumn;
                    ASPxCheckBox chk = (ASPxCheckBox)grvpResult.FindRowCellTemplateControl(i, column1, "chkCheck");
                    HiddenField hdfId = (HiddenField)grvpResult.FindRowCellTemplateControl(i, column1, "hdfUserID");

                    if (chk.Checked == true)
                    {
                        index = index + 1;
                        array = array + hdfId.Value+ ";"+index+":";
                        
                    }
                }
                dx.sp_updateCSS(array, b);
                dx.SubmitChanges();
            }
            catch (Exception) { }
            finally { dx.Connection.Close(); }
        }

       
    }
}